package day14;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket server = new ServerSocket(9999);
        while (true){
            Socket client = server.accept();
            //通过线程 模拟每个客户端连接之后 读写的逻辑
            new ServerThread1(client).start();
        }
    }
}
//只负责接受每个客户端 写入多次的数据
class ServerThread1 extends Thread{
    Socket client;
    public ServerThread1(Socket client){
        this.client = client;
    }
    public void run() {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
            while (true){
                String msg = br.readLine();
                System.out.println(client.getInetAddress()+":"+msg);
            }
        } catch (Exception e) {

        }
    }
}